﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "UrlStat")]
    public class UrlStatInfo : IDetach
    {
        public UrlStatInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private int _userid = 0;
        private string _username = "";
        private int _usertype = 0;
        private string _url = "";
        private DateTime _startviewtime = DateTime.Now;
        private DateTime _endviewtime = DateTime.Now;
        private int _viewsecticks = 0;
        private string _urlName = "";

        private EntityRef<StudentInfo> _studentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_studentInfo", ThisKey = "UserId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public StudentInfo StudentInfo
        {
            get { return UserType == 1 ? _studentInfo.Entity : null; }
            set { _studentInfo.Entity = value; }
        }

        private EntityRef<TeacherInfo> _teacherInfo;
        [System.Data.Linq.Mapping.Association(Storage = "_teacherInfo", ThisKey = "UserId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public TeacherInfo TeacherInfo
        {
            get { return UserType >= 2 ? _teacherInfo.Entity : null; }
            set { _teacherInfo.Entity = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int UserId
        {
            set { _userid = value; }
            get { return _userid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string UserName
        {
            set { _username = value; }
            get { return _username; }
        }
        /// <summary>
        /// 1学生2负责教师3主讲教师4助教
        /// </summary>
        [Column]
        public int UserType
        {
            set { _usertype = value; }
            get { return _usertype; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string Url
        {
            set { _url = value; }
            get { return _url; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime StartViewTime
        {
            set { _startviewtime = value; }
            get { return _startviewtime; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime EndViewTime
        {
            set { _endviewtime = value; }
            get { return _endviewtime; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int ViewSecTicks
        {
            set { _viewsecticks = value; }
            get { return _viewsecticks; }
        }

        [Column]
        public string UrlName
        {
            set { _urlName = value; }
            get { return _urlName; }
        }

        #endregion Model

        public void Detach()
        {
            this._studentInfo = default(EntityRef<StudentInfo>);
            this._teacherInfo = default(EntityRef<TeacherInfo>);
        }
    }
}
